package exercise8;

import java.io.*;

public class Exercise17_10 {
    public static void main(String []args) throws IOException {
        String filepath=args[0];
        int num=Integer.parseInt(args[1]);

        BufferedInputStream input=new BufferedInputStream(new FileInputStream(filepath));

        int size= (int) Math.ceil(1.0*input.available()/num);

        for (int i=1;i<=num;i++){
            BufferedOutputStream output=new BufferedOutputStream(new FileOutputStream(filepath+"."+i));
            int value;
            int count = 0;
            while (count++ < size && (value = input.read()) != -1) {
                output.write(value);
            }
        }
    }
}
